<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Home\Controller;
use OT\DataDictionary;

/**
 * 前台首页控制器
 * 主要获取首页聚合数据
 */
class XinxiController extends HomeController {

      public function index(){
         // print_R($_SESSION);
          $index = M('company');
          $id = $_SESSION['home']['user_auth']['uid'];
          // $cid = $_SESSION['home']['cid'];
          $count = $index->where(array('uid'=>$id))->count();// 查询满足要求的总记录数
          // var_dump($index);
          $Page = new \Think\Page($count,5);// 实例化分页类 传入总记录数和每页显示的记录数(10)
          $Page->setConfig('prev','上一页');
          $Page->setConfig('next','下一页');
          $Page->setConfig('last','末页');
          $Page->setConfig('first','首页');
          $Page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
          $show = $Page->show();// 分页显示输出

          foreach($map1 as $key=>$val) {
                $Page->parameter[$key] = urlencode($val);
              }

          $list = $index->where(array('uid'=>$id))->limit($Page->firstRow.','.$Page->listRows)->select();

          // var_dump($list);
          // var_dump($_SESSION);

          // $list = $index ->where(array('cid' =>$cid)) ->select();
          $this ->assign('list',$list);
          $this ->assign('page',$show);
          //var_dump($_SESSION);
          $this ->display('Xinxi/index');



          // $company = M('company');
            // $list = $company ->where(array('uid'=>$id))->select();

      }



    /*描述编辑*/
    public function desAction(){
      $desAction = M('description');
      $id = $_POST['id']; 
      $desAction ->create();
      $val = $desAction ->where(array('id'=>$id)) ->save();
      // var_dump($_POST);
      // var_dump($val);
      if($val){
        $this ->redirect('xinxi/more');
      }else{
        $this ->error();
      }
    }


    /*公司描述*/
    public function des(){
      $des = M('description');
      // $cid = $_GET['cid'];
      $cid = $_SESSION['home']['cid'];
      // var_dump($cid);
      $list = $des ->where(array('cid'=>$cid))->select();
      // var_dump($list);

      $this ->assign('list',$list);
      $this ->display('xinxi/des');

    }



    /*logo/经营范围编辑*/
    public function picAction(){
      $picAction = M('pic');
      $id = $_POST['id']; 
      $picAction ->create();
      $val = $picAction ->where(array('id'=>$id)) ->save();
      // var_dump($_POST);
      // var_dump($val);
      if($val){
        $this ->redirect('xinxi/more');
      }else{
        $this ->error();
      }
    }

    /*logo/经营范围*/
    public function pic(){
      $pic =M('pic');
      // $cid = $_GET['cid'];
      $cid = $_SESSION['home']['cid'];
      $list = $pic ->where(array('cid'=>$cid)) ->select();

      $this ->assign('list',$list);
      $this ->display('xinxi/pic');
    }

    /*联系人编辑提交*/
    public function contactAction(){
      $contactAction = M('contact');
      $id = $_POST['id']; 
      $contactAction ->create();
      $val = $contactAction ->where(array('id'=>$id)) ->save();
      // var_dump($_POST);
      // var_dump($val);
      // exit;
      if($val){
        $this ->redirect('xinxi/more');
      }else{
        $this ->error();
      }
    }


    /*联系人方式编辑页面*/
    public function contactedit(){
     $contactedit = M('contact');
     // var_dump($_GET);
     // $cid = $_GET['cid'];
     $cid = $_SESSION['home']['cid'];
     $id = $_GET['id'];
     $list = $contactedit ->where(array('cid'=>$cid,'id'=>$id))->select();
     
     $this ->assign('list',$list);
     $this ->display('xinxi/contactedit');
    }




    /*联系方式*/
    public function contact(){
      $contact = M('contact');
      // $cid = $_GET['cid'];
      $cid = $_SESSION['home']['cid'];

      $list = $contact ->where(array('cid'=>$cid)) ->select();
      // var_dump($list);
      $this ->assign('list',$list);
      $this ->display('xinxi/contact');
    }

    /*公司信息编辑提交*/
    public function editAction(){
      $editAction = M('company');
      $id = $_POST['id']; 
      $editAction ->create();
      $val = $editAction ->where(array('id'=>$id)) ->save();
      // var_dump($_POST);
      // var_dump($val);
      // exit;
      if($val){
        $this ->redirect('index/index');
      }else{
        $this ->error();
      }
    }

	  // 信息编辑
    public function edit()
    {        
        $edit = M('company');
        // var_dump($_GET);
        $cid = $_SESSION['home']['cid'];
        $list = $edit ->where(array('id'=>$cid))->select();  
        // var_dump($list);
        $this->assign('list',$list);
        $this->display('xinxi/edit');
    }

    // 更多
    public function more(){
      // var_dump($_GET);
      $cid = $_GET['cid'];
      $_SESSION['home']['cid'] = $cid;

      // $this ->assign('v',$cid);

      $this ->display('xinxi/more');

    }

   
  

}